package net.yangyy.os.common.resp;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author zhaox 2021/7/14
 * @version 1.0.0
 */
@Data
public class ResultData<T> implements Serializable {

    private int code;

    private String message;

    private T data;

    private List<T> list;

    private boolean success;

    public static <T> ResultData<T> fail(int code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }

    public static <T> ResultData<T> success(String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(200);
        resultData.setMessage(message);
        return resultData;
    }

    public static <T> ResultData<T> list(List<T> list) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(200);
        resultData.setMessage("操作成功");
        resultData.setList(list);
        return resultData;
    }

    public static <T> ResultData<T> data(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(200);
        resultData.setMessage("操作成功");
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> dataAndList(List<T> list, T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(200);
        resultData.setMessage("操作成功");
        resultData.setData(data);
        resultData.setList(list);
        return resultData;
    }
}
